home *** CD-ROM | disk | FTP | other *** search
- Path: cls.net!news
- From: damian@sup.de (Damian Gruszka)
- Newsgroups: comp.lang.c
- Subject: Re: help with strcmp
- Date: 3 Apr 1996 10:57:59 GMT
- Organization: sup.de
- Message-ID: <4jtljo$k33@freeside.cls.de>
- References: <4jpiek$lp6@blaze.cs.jhu.edu>
- NNTP-Posting-Host: kldos3.sup.de
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.11
-
- In article <4jpiek$lp6@blaze.cs.jhu.edu>, lasher@hops.cs.jhu.edu says...
- >
- >For some reason when I try to compare the strings in the following
- >snippet I consistently get a core dump (running on a UNIX machine running
- >Solaris). Could anyone point out what may be going wrong? I have run it
- >through the debugger and that was no help at all for me. here is the
- >code snippet:
- >
- >#include <stdio.h>
- >#include <stdlib.h>
- >#include <string.h>
- >
- >void setup(FILE *);
- >
- >void main(int argc, char *argv[])
- >{
- >char buf[20], data[40], *buff, *arg, *fp;
- >FILE *handle, *dest;
- >int n;
- >
- >handle = fopen(argv[1], "r");
- >if(dest = fopen( "dbuild.out", "w")) setup(dest);
- >
- >while(!feof(handle)) {
- > n = 0;
- > fp = fgets(data, 40, handle);
- > if ( strcasecmp(fp, "<action>\n") == 0) /* the coredump is here
- */
- > parseAction(handle, dest);
- > else if ( strcasecmp(fp, "<control>\n") == 0)
- > parseControl(handle, dest);
- > else if ( strcasecmp(fp, "<general>\n") == 0)
- > parseGeneral(handle, dest);
- > printf("%s", data);
- > }
- >fclose(dest);
- >
- >}
- >
- >
- >--
- >John Davis
- >lasher@hops.cs.jhu.edu
- >http://hops.cs.jhu.edu/~lasher
- >
- >UNIX is a very user-friendly operating system
- > it's just picky about who it's friends with.
- You can also test fp against NULL.fgets can return NULL and than
- the EOF or Error flag will be set.
-
- damian
- damian@sup.de
-
-